******************************************************************************************
*																					     * 	
*   Honor Among Thieves: Understanding Rhetorical and Material Cooperation Among		 *
*   Violent Non-State Actors 															 *													
*  																						 *
*   December 2020																	     *
*																						 *	
*	By: Blair, Chenoweth, Horowitz, Perkoski, and Potter								 *
*  																						 *
*  																						 *
******************************************************************************************

clear all
set more off
macro drop _all
set matsize 800
set seed 8675309
set scheme plotplainblind

*cd "~/Dropbox/MGAR Cleanup October 2017/Replication Files/"

global orgdyad "capratiomiss_undir sharedsponsor_lag1 agediff age1 age2 ln_dist"

global orgdyad0 "capratio_undir sharedsponsor_lag1 agediff age1 age2 ln_dist"

global country "polity1_lag1 politysquared1_lag1 polity2_lag1 politysquared2_lag1 ethfrac1 ethfrac2 ln_pop1_lag1 ln_pop2_lag1 ln_gdppc1_lag1 ln_gdppc2_lag1 ln_ustroops1_lag1 ln_ustroops2_lag1"

global region "africa1 africa2 asia1 asia2 europe1 europe2 northamerica1 northamerica2 southamerica1 southamerica2"

global sumstat "sharedideo2 corelgdyad2 leftcommdyad natsepdyad rightdyad envirodyad i.contentordermiss0 content2 opsupp2 matsupp2 terrsupp2 trainsupp2 finsupp2 allies associates supporters hosts fans rivals enemies capratio0 capratio0squared sharedsponsor agediff age1 age2 repression samestatedyad samecontig transnational2"


***************************************** DESCRIPTIVE FIGURES *********************************************************************************

use "relationshipdyads_undirected.dta", replace

preserve

keep if alliance==1

collapse (sum) sharedideo2 corelgdyad2 natsepdyad leftcommdyad sharedcomm rightdyad continitiation contmatinit contrhetinit contmat contrhet rivals enemies competition samestatemat samestaterhet samecontigmat samecontigrhet transmat transrhet alliance init (max) totaldyads newdyads totaltrans totalsamecontig gtdnum, by(year)

keep if year>=1965

gen sharematerial= contmat/totaldyads
gen sharerhetorical= contrhet/totaldyads
gen sharealliance= alliance/totaldyads

twoway line contrhet contmat alliance year if year>=1965, ylabel(0(25)250, angle(h) tlength(*1.45)) xtitle("Year", size(medsmall)) xlabel(1965(5)2016, angle(h) tlength(*1.45)) xmtick(1965(1)2016, tlength(*1.75)) legend(off) ytitle("Ongoing Cooperative Relationships", size(medsmall)) yline(250, lcolor(gs10) lpatt(. . .)) lcolor(gs10 gs7 gs0) lpatt(dash dash_dot solid) text(242.5 2008 "Total Alliances", size(small)) text(50 2009 "Rhetorical Alliances", size(small)) text(148.5 2009 "Material Alliances", size(small)) saving("/Users/christopherblair/Dropbox/MGAR Cleanup October 2017/Post APSA 2018/IO R&R/Final Figures/totalalliances.gph", replace)

twoway line sharerhetorical sharematerial sharealliance year if year>=1965, ylabel(0(.0001).001, angle(h) tlength(*1.45)) xtitle("Year", size(medsmall)) xlabel(1965(5)2016, angle(h) tlength(*1.45)) xmtick(1965(1)2016, tlength(*1.75)) legend(off) ytitle("Ongoing Cooperative Relationships as Proportion of All Dyads", size(medsmall)) yline(.001, lcolor(gs10) lpatt(. . .)) lcolor(gs10 gs7 gs0) lpatt(dash dash_dot solid) text(.0006 2010 "Total Alliances", size(small)) text(.0001 2010 "Rhetorical Alliances", size(small)) text(.0003 2010 "Material Alliances", size(small)) saving("/Users/christopherblair/Dropbox/MGAR Cleanup October 2017/Post APSA 2018/IO R&R/Final Figures/sharealliances.gph", replace)

graph combine "totalalliances.gph" "sharealliances.gph", iscale(*.85) saving("alliances.gph", replace)

gen sharerelg= corelgdyad2/totaldyads
gen sharenatsep= natsepdyad/totaldyads
gen shareleftcomm = leftcommdyad/totaldyads

twoway line leftcommdyad natsepdyad corelgdyad2 alliance year if year>=1965, ylabel(0(25)250, angle(h) tlength(*1.45)) xtitle("Year", size(medsmall)) xlabel(1965(5)2020, angle(h) tlength(*1.45)) xmtick(1965(1)2016, tlength(*1.75)) legend(off) ytitle("Ongoing Cooperative Relationships", size(medsmall)) yline(250, lcolor(gs10) lpatt(. . .)) lcolor(orangebrown midblue cranberry gs0) lpatt(solid solid solid solid) text(177.5 2019 "Total" "Alliances", size(vsmall)) text(70 2019 "Nationalist""Alliances", size(vsmall)) text(19 2019 "Leftist""Alliances", size(vsmall)) text(130 2019 "Co-Religious" "Alliances", size(vsmall))  saving("/Users/christopherblair/Dropbox/MGAR Cleanup October 2017/Post APSA 2018/IO R&R/Final Figures/totaltype.gph", replace)

twoway line shareleftcomm sharenatsep sharerelg sharealliance year if year>=1965, ylabel(0(.0001).001, angle(h) tlength(*1.45)) xtitle("Year", size(medsmall)) xlabel(1965(5)2020, angle(h) tlength(*1.45)) xmtick(1965(1)2016, tlength(*1.75)) legend(off) ytitle("Ongoing Cooperative Relationships as Proportion of All Dyads", size(medsmall)) yline(.001, lcolor(gs10) lpatt(. . .)) lcolor(orangebrown midblue cranberry gs0) lpatt(solid solid solid solid) text(.000625 2019 "Total" "Alliances", size(vsmall)) text(.00025 2019 "Nationalist""Alliances", size(vsmall)) text(.00006 2019 "Leftist""Alliances", size(vsmall)) text(.00045 2019 "Co-Religious" "Alliances", size(vsmall))  saving("/Users/christopherblair/Dropbox/MGAR Cleanup October 2017/Post APSA 2018/IO R&R/Final Figures/sharetype.gph", replace)

graph combine "totaltype.gph" "sharetype.gph", iscale(*.85) saving("type.gph", replace)

gen shareinitmat= contmatinit/totaldyads
gen shareinitrhet= contrhetinit/totaldyads

twoway line contrhetinit contmatinit year if year>=1965, ylabel(0(2)30, angle(h) tlength(*1.45)) xtitle("Year", size(medsmall)) xlabel(1965(5)2020, angle(h) tlength(*1.45)) xmtick(1965(1)2016, tlength(*1.75))  legend(off) ytitle("Cooperative Relationships Initiated", size(medlarge)) lcolor(gs10 gs0) lpatt(solid solid) text(13.5 2018 "Material""Alliances", size(vsmall)) text(5 2018 "Rhetorical""Alliances", size(vsmall)) saving("/Users/christopherblair/Dropbox/MGAR Cleanup October 2017/Post APSA 2018/IO R&R/Final Figures/totalinitiation.gph", replace)

twoway line shareinitrhet shareinitmat year if year>=1965, ylabel(0(.000025).0003, angle(h) tlength(*1.45)) xtitle("Year", size(medsmall)) xlabel(1965(5)2020, angle(h) tlength(*1.45)) xmtick(1965(1)2016, tlength(*1.75)) legend(off) ytitle("Cooperative Relationships Initiated as Proportion of All Dyads", size(medlarge)) lcolor(gs10 gs0) lpatt(solid solid) yline(.0003, lcolor(gs10) lpatt(. . .)) text(.00001 2018 "Rhetorical""Alliances", size(vsmall)) text(.00006 2015 "Material""Alliances", size(vsmall)) saving("/Users/christopherblair/Dropbox/MGAR Cleanup October 2017/Post APSA 2018/IO R&R/Final Figures/shareinitiation.gph", replace)

graph combine "totalinitiation.gph" "shareinitiation.gph", iscale(*.85) saving("initiation.gph", replace)

twoway line contrhetinit contmatinit year if year>=1965, ylabel(0(2)30, angle(h) tlength(*1.45)) xtitle("Year", size(medsmall)) xlabel(1965(5)2020, angle(h) tlength(*1.45)) xmtick(1965(1)2016, tlength(*1.75))  legend(off) ytitle("Cooperative Relationships Initiated", size(medlarge)) || line gtdnum year if year>=1970, yaxis(2) lcolor(gs10 gs0 gs10) lpatt(solid dash solid) text(13.5 2018 "Material""Alliances", size(vsmall)) text(5 2018 "Rhetorical""Alliances", size(vsmall)) saving("/Users/christopherblair/Dropbox/MGAR Cleanup October 2017/Post APSA 2018/IO R&R/Final Figures/gtdinittotal.gph", replace)
twoway line shareinitrhet shareinitmat year if year>=1965, ylabel(0(.000025).0003, angle(h) tlength(*1.45)) xtitle("Year", size(medsmall)) xlabel(1965(5)2020, angle(h) tlength(*1.45)) xmtick(1965(1)2016, tlength(*1.75)) legend(off) ytitle("Cooperative Relationships Initiated as Proportion of All Dyads", size(medlarge)) || line gtdnum year if year>=1970, yaxis(2) lcolor(gs10 gs0 gs10) lpatt(solid dash solid) text(.000075 2018 "Material""Alliances", size(vsmall)) text(.00001 2018 "Rhetorical""Alliances", size(vsmall))  saving("/Users/christopherblair/Dropbox/MGAR Cleanup October 2017/Post APSA 2018/IO R&R/Final Figures/gtdinitshare.gph", replace)

graph combine "gtdinittotal.gph" "gtdinitshare.gph", iscale(*.85) saving("gtdinit.gph", replace)


foreach x of var samecontigmat samecontigrhet {
gen share`x'= `x'/totalsamecontig
}

foreach x of var transmat transrhet {
gen share`x'= `x'/totaltrans 
}

twoway line samecontigmat samecontigrhet transmat transrhet year if year>=1965, ylabel(0(10)150, angle(h) tlength(*1.45)) xtitle("Year", size(medlarge)) xlabel(1965(5)2020, angle(h) tlength(*1.45)) xmtick(1965(1)2016, tlength(*1.75)) yline(150, lcolor(gs10) lpatt(. . .)) legend(off) ytitle("Ongoing Cooperative Relationships", size(medlarge)) lcolor(gs0 gs0 gs10 gs10) lpatt(solid dash solid dash) text(100 2018 "Domestic""Material", size(vsmall)) text(55 2018 "Transnational""Material", size(vsmall)) text(2.5 2018.5 "Domestic""Rhetorical", size(vsmall)) text(22.5 2018 "Transnational""Rhetorical", size(vsmall)) saving("/Users/christopherblair/Dropbox/MGAR Cleanup October 2017/Post APSA 2018/IO R&R/Final Figures/areaalliances.gph", replace)

twoway line sharesamecontigmat sharesamecontigrhet year if year>=1965, ylabel(0(.0005).01, angle(h) tlength(*1.45)) xtitle("Year", size(medsmall)) xlabel(1965(5)2016, angle(h) tlength(*1.45)) xmtick(1965(1)2016, tlength(*1.75)) yline(.01, lcolor(gs10) lpatt(. . .)) legend(off) ytitle("Ongoing Domestic Cooperative Relationships as" "Proportion of Same Region Dyads", size(medlarge)) lcolor(gs0 gs0 gs10 gs10) lpatt(solid dash solid dash) text(.003 2011 "Material""Alliances", size(vsmall)) text(.001 2011 "Rhetorical""Alliances", size(vsmall)) saving("/Users/christopherblair/Dropbox/MGAR Cleanup October 2017/Post APSA 2018/IO R&R/Final Figures/regionshare.gph", replace)

twoway line sharetransmat sharetransrhet year if year>=1965, ylabel(0(.00005).0005, angle(h) tlength(*1.45)) xtitle("Year", size(medlarge)) xlabel(1965(5)2016, angle(h) tlength(*1.45)) xmtick(1965(1)2016, tlength(*1.75)) yline(.0005, lcolor(gs10) lpatt(. . .)) legend(off) ytitle("Ongoing Transnational Cooperative Relationships as" "Proportion of Transnational Dyads", size(medlarge)) lcolor(gs0 gs0 gs10 gs10) lpatt(solid dash solid dash) text(.0002 2011 "Material""Alliances", size(vsmall)) text(.00005 2011 "Rhetorical""Alliances", size(vsmall)) saving("/Users/christopherblair/Dropbox/MGAR Cleanup October 2017/Post APSA 2018/IO R&R/Final Figures/transshare.gph", replace)

graph combine "regionshare.gph" "transshare.gph", iscale(*.85) saving("areashare.gph", replace)

restore

preserve

collapse (sum) sharedideo2 corelgdyad2 natsepdyad leftcommdyad sharedcomm rightdyad continitiation contmatinit contrhetinit contmat contrhet rivals enemies competition samestatemat samestaterhet samecontigmat samecontigrhet transmat transrhet alliance init (max) totaldyads newdyads totaltrans totalsamecontig gtdnum, by(year)

keep if year>=1965

gen sharealliance= alliance/totaldyads
gen sharecompete= competition/totaldyads

twoway line alliance competition year if year>=1965, ylabel(0(25)250, angle(h) tlength(*1.45)) xtitle("Year", size(medlarge)) xlabel(1965(5)2016, angle(h) tlength(*1.45)) xmtick(1965(1)2016, tlength(*1.75)) legend(off) ytitle("Ongoing Relationships", size(medlarge)) yline(250, lcolor(gs10) lpatt(. . .)) lcolor(gs0 gs10) lpatt(solid solid) text(242.5 2008 "Total Alliances", size(small)) text(55 2009 "Total Rivalries", size(small)) saving("/Users/christopherblair/Dropbox/MGAR Cleanup October 2017/Post APSA 2018/IO R&R/Final Figures/totalrelationships.gph", replace)

twoway line sharealliance sharecompete year if year>=1965, ylabel(0(.0001).001, angle(h) tlength(*1.45)) xtitle("Year", size(medlarge)) xlabel(1965(5)2016, angle(h) tlength(*1.45)) xmtick(1965(1)2016, tlength(*1.75)) legend(off) ytitle("Ongoing Relationships as Proportion of All Dyads", size(medlarge)) yline(.001, lcolor(gs10) lpatt(. . .)) lcolor(gs0 gs10) lpatt(solid dash) text(.0006 2010 "Total Alliances", size(small)) text(.0002 2010 "Total Rivalries", size(small)) saving("/Users/christopherblair/Dropbox/MGAR Cleanup October 2017/Post APSA 2018/IO R&R/Final Figures/sharerelationships.gph", replace)

graph combine "totalrelationships.gph" "sharerelationships.gph", iscale(*.85) saving("relationships.gph", replace)

restore

clear


************************************** COMPETING RISKS **********************************************

use "mgarduration_undirected.dta", replace

xtset undir_id year

*gen compete=0
*replace compete=1 if l.contentorder==1 & contentorder==0
*replace compete=2 if l.contentorder==2 & contentorder==0
*replace compete=3 if l.contentorder==1 & contentorder==2
*replace compete=4 if l.contentorder==2 & contentorder==1

*order typeorder, a(contentorder)

stset matend, fail(compete==2)

eststo matcompete: stcrreg sharedideo2##c.fariss $orgdyad0 $country nummat, cluster(undir_id) compete(compete==3)

stset rhetend, fail(compete==1)

eststo rhetcompete: stcrreg sharedideo2##c.fariss $orgdyad0 $country numrhet, cluster(undir_id) compete(compete==4)

esttab rhetcompete matcompete using compete.tex, replace t(3) legend label collabels(none) varlabels(_cons Constant) se(3) pr2 b(3) star(* 0.10 ** 0.05 *** 0.01)


************************************** PARAMETRIC HAZARD MODELS **********************************************


stset matend, failure(compete==2)

eststo matexp: streg sharedideo2##c.fariss $orgdyad0 $country nummat, distribution(exp) nohr vce(cl undir_id)

eststo matweib: streg sharedideo2##c.fariss $orgdyad0 $country nummat, distribution(weib) nohr vce(cl undir_id)

eststo matgomp: streg sharedideo2##c.fariss $orgdyad0 $country nummat, distribution(gomp) nohr vce(cl undir_id)

stset rhetend, failure(compete==1)

eststo rhetexp: streg sharedideo2##c.fariss $orgdyad0 $country numrhet, distribution(exp) nohr vce(cl undir_id)

eststo rhetweib: streg sharedideo2##c.fariss $orgdyad0 $country numrhet, distribution(weib) nohr vce(cl undir_id)

eststo rhetgomp: streg sharedideo2##c.fariss $orgdyad0 $country numrhet, distribution(gomp) nohr vce(cl undir_id)

coefplot (rhetexp, connect() lpatt(solid)lcol(black)msymbol(T)msize(medlarge)mcol(black)ciopts(lpatt(solid)lcol(black))) (rhetweib, connect() lpatt(solid)lcol(black)msymbol(O)msize(medlarge)mcol(black)ciopts(lpatt(solid)lcol(black))) (rhetgomp, connect() lpatt(solid)lcol(black)msymbol(S)msize(medlarge)mcol(black)ciopts(lpatt(solid)lcol(black))), drop($orgdyad0 $country numrhet nummat _cons) ci(95 90) vert yline(0, lcolor(cranberry) lpatt(shortdash)) ylabel(-20(2)10) ytitle(Standardized Coefficient) yline(-20, lcolor(gs10) lpatt(dot)) legend(off) title("Rhetorical Alliance Breakdown")  xlabel(1 "Shared Ideology" 2 "Repression" 3 "Shared Ideology x Repression") saving(rhetparametric.gph, replace)
coefplot (matexp, connect() lpatt(solid)lcol(black)msymbol(T)msize(medlarge)mcol(black)ciopts(lpatt(solid)lcol(black))) (matweib, connect() lpatt(solid)lcol(black)msymbol(O)msize(medlarge)mcol(black)ciopts(lpatt(solid)lcol(black))) (matgomp, connect() lpatt(solid)lcol(black)msymbol(S)msize(medlarge)mcol(black)ciopts(lpatt(solid)lcol(black))), drop($orgdyad0 $country numrhet nummat _cons) ci(95 90) vert yline(0, lcolor(cranberry) lpatt(shortdash)) ylabel(-2(.5)4) ytitle(Standardized Coefficient) yline(4, lcolor(gs10) lpatt(dot)) legend(off) title("Material Alliance Breakdown", size(medlarge)) yline(-2, lcolor(gs10)lpatt(dot)) xlabel(1 "Shared Ideology" 2 "Repression" 3 "Shared Ideology x Repression") saving(matparametric.gph, replace)

graph combine "rhetparametric.gph" "matparametric.gph", iscale(*.85) saving("parametric.gph", replace)

clear

************************************ REMAINING ANALYSES MUST BE RUN ON CLUSTER SERVER ******************************************************

* Server Access in Terminal*

*ssh -A cwblair@gpc.sas.upenn.edu

*	Enter Password

*qlogin
*module load stata/14
*stata

clear all
set more off
macro drop _all
set matsize 800
set seed 8675309
set scheme plotplainblind

use mgar_final_undirected.dta, clear

estimates drop _all

sort undir_id year
xtset undir_id year

global orgdyad "capratiomiss_undir sharedsponsor_lag1 agediff age1 age2 ln_dist"

global orgdyad0 "capratio_undir sharedsponsor_lag1 agediff age1 age2 ln_dist"

global country "polity1_lag1 politysquared1_lag1 polity2_lag1 politysquared2_lag1 ethfrac1 ethfrac2 ln_pop1_lag1 ln_pop2_lag1 ln_gdppc1_lag1 ln_gdppc2_lag1 ln_ustroops1_lag1 ln_ustroops2_lag1"

global region "africa1 africa2 asia1 asia2 europe1 europe2 northamerica1 northamerica2 southamerica1 southamerica2"

global sumstat "sharedideo2 corelgdyad2 leftcommdyad natsepdyad rightdyad envirodyad contentordermiss0 content2 opsupp2 matsupp2 terrsupp2 trainsupp2 finsupp2 allies associates supporters hosts fans rivals enemies capratio_undir sharedsponsor agediff age1 age2 repression fariss samestatedyad samecontig transnational2"

sum

************************************** SUMMARY STATISTICS **********************************************


estpost sum $sumstat

esttab using "sumstat.tex", label title(Summary Statistics) cells("count mean sd min max") replace

estpost sum $sumstat if alliance==1

esttab using "sumstat_alliance.tex", label title(Summary Statistics) cells("count mean sd min max") replace

estpost sum continitiation contentordermiss0 $orgdyad0 $country

esttab using "sumstat_si.tex", label title(Summary Statistics) cells("count mean sd min max") replace


************************************** CROSS-TABS **********************************************

corr typeordermiss0 contentordermiss0

table typeordermiss0 contentordermiss0

table reltype contentordermiss0


************************************** HISTOGRAMS OF REPRESSION **********************************************

hist fariss, percent saving(fariss_hist.gph)

hist repression, percent saving(ciri_hist.gph)

************************************** MODELING CONTENT MISSINGNESS **********************************************


eststo miss1: logit contmiss c.fariss i.sharedideo2 $orgdyad0 $country, cluster(undir_id)
eststo miss2: logit contmiss c.fariss##i.sharedideo2 $orgdyad0 $country, cluster(undir_id)

esttab miss1 miss2 using missingness.tex, replace t(3) legend label collabels(none) varlabels(_cons Constant) se(3) pr2 b(3) star(* 0.10 ** 0.05 *** 0.01) mtitles("All Dyads" "All Dyads")


************************************** Main Models -- Shared Ideology (by Content) **********************************************


eststo cinit1: mlogit continitiation c.fariss i.sharedideo2 $orgdyad0 $country, cluster(undir_id) base(0)
eststo cinit2: mlogit continitiation c.fariss##i.sharedideo2 $orgdyad0 $country, cluster(undir_id) base(0)
esttab cinit1 cinit2 using sharedideo_cinit.tex, replace t(3) legend label collabels(none) varlabels(_cons Constant) se(3) pr2 b(3) star(* 0.10 ** 0.05 *** 0.01) mtitles("All Dyads" "Within Country" "Within Region" "Transnational")

*est resto cinit2
*eststo cinit2marg0: margins, dydx(sharedideo2) atmeans predict(outcome(0)) post vsquish

est resto cinit2
eststo cinit2marg0: margins, dydx(sharedideo2) at(fariss=(.9509563  2.559293)) atmeans predict(outcome(0)) post vsquish

*est resto cinit2
*eststo cinit2marg1: margins, dydx(sharedideo2) atmeans predict(outcome(1)) post vsquish

est resto cinit2
eststo cinit2marg1: margins, dydx(sharedideo2) at(fariss=(.9509563  2.559293)) atmeans predict(outcome(1)) post vsquish

*est resto cinit2
*eststo cinit2marg2: margins, dydx(sharedideo2) atmeans predict(outcome(2)) post vsquish

est resto cinit2
eststo cinit2marg2: margins, dydx(sharedideo2) at(fariss=(.9509563  2.559293)) atmeans predict(outcome(2)) post vsquish

coefplot (cinit2marg0, mcolor(gs0) msymbol(O)) || (cinit2marg1, mcolor(gs10) msymbol(D))  || (cinit2marg2, mcolor(gs0) msymbol(S)) , yline(0, lcolor(cranberry) lpatt(shortdash)) vertical byopts(row(1)) levels(95 90) ytitle("AME of Shared Ideology", size(medsmall)) ylabel(-.00005(.00001).00005) yline(.00005, lcolor(gs10) lpatt(dot)) yline(-.00005, lcolor(gs10) lpatt(dot)) saving(initmargins1.gph, replace)


************************************** Main Models -- Disaggregating Ideology (by Content) **********************************************

eststo cinit7: mlogit continitiation c.fariss##i.corelgdyad2 $orgdyad0 polity1_lag1 politysquared1_lag1 polity2_lag1 politysquared2_lag1 ethfrac1 ethfrac2 if post911==1, cluster(undir_id) base(0)
esttab cinit7 using corelg_cinit.tex, replace t(3) legend label collabels(none) varlabels(_cons Constant) se(3) pr2 b(3) star(* 0.10 ** 0.05 *** 0.01) mtitles("All Dyads" "Within Country" "Within Region" "Transnational")

eststo cinit12: mlogit continitiation c.fariss##i.leftcommdyad $orgdyad0 polity1_lag1 politysquared1_lag1 polity2_lag1 politysquared2_lag1 ethfrac1 ethfrac2 if coldwar==1, cluster(undir_id) base(0)
esttab cinit12 using leftcomm_cinit.tex, replace t(3) legend label collabels(none) varlabels(_cons Constant) se(3) pr2 b(3) star(* 0.10 ** 0.05 *** 0.01) mtitles("All Dyads" "Within Country" "Within Region" "Transnational")

eststo cinit22: mlogit continitiation c.fariss##i.natsepdyad $orgdyad0 $country, cluster(undir_id) base(0)
eststo cinit27: mlogit continitiation c.fariss##i.rightdyad $orgdyad0 $country, cluster(undir_id) base(0)
eststo cinit32: mlogit continitiation c.fariss##i.envirodyad $orgdyad0 $country, cluster(undir_id) base(0)

esttab cinit22 cinit27 cinit32 using other_cinit.tex, replace t(3) legend label collabels(none) varlabels(_cons Constant) se(3) pr2 b(3) star(* 0.10 ** 0.05 *** 0.01) mtitles("All Dyads" "Within Country" "Within Region" "Transnational")


**** Marginal Effects of Different Ideologies


est resto cinit7
eststo cinit7marg0: margins, dydx(corelgdyad2) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(0)) post vsquish

est resto cinit7
eststo cinit7marg1: margins, dydx(corelgdyad2) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(1)) post vsquish

est resto cinit7
eststo cinit7marg2: margins, dydx(corelgdyad2) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(2)) post vsquish

coefplot (cinit7marg0, mcolor(gs0) msymbol(O)) || (cinit7marg1, mcolor(gs10) msymbol(D))  || (cinit7marg2, mcolor(gs0) msymbol(S)) , yline(0, lcolor(cranberry) lpatt(shortdash)) vertical byopts(row(1)) levels(95 90) ytitle("AME of Shared Religion", size(medsmall)) ylabel(-.00014(.00002).00014) saving(initmargins2.gph, replace)


est resto cinit12
eststo cinit12marg0: margins, dydx(leftcommdyad) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(0)) post vsquish

est resto cinit12
eststo cinit12marg1: margins, dydx(leftcommdyad) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(1)) post vsquish

est resto cinit12
eststo cinit12marg2: margins, dydx(leftcommdyad) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(2)) post vsquish

coefplot (cinit12marg0, mcolor(gs0) msymbol(O)) || (cinit12marg1, mcolor(gs10) msymbol(D))  || (cinit12marg2, mcolor(gs0) msymbol(S)) ,  yline(0, lcolor(cranberry) lpatt(shortdash)) vertical byopts(row(1)) levels(95 90) ytitle("AME of Shared Leftism", size(medsmall)) ylabel(-.00018(.00003).00018) saving(initmargins3.gph, replace)


est resto cinit22
eststo cinit22marg0: margins, dydx(natsepdyad) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(0)) post vsquish

est resto cinit22
eststo cinit22marg1: margins, dydx(natsepdyad) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(1)) post vsquish

est resto cinit22
eststo cinit22marg2: margins, dydx(natsepdyad) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(2)) post vsquish

coefplot (cinit22marg0, mcolor(gs0) msymbol(O)) || (cinit22marg1, mcolor(gs10) msymbol(D))  || (cinit22marg2, mcolor(gs0) msymbol(S)) ,  yline(0, lcolor(cranberry) lpatt(shortdash)) vertical byopts(row(1)) levels(95 90) ytitle("AME of Shared Nationalism", size(medsmall)) ylabel(-.00003(.000005).00004) saving(initmargins4.gph, replace)


est resto cinit27
eststo cinit27marg0: margins, dydx(rightdyad) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(0)) post vsquish

est resto cinit27
eststo cinit27marg1: margins, dydx(rightdyad) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(1)) post vsquish

est resto cinit27
eststo cinit27marg2: margins, dydx(rightdyad) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(2)) post vsquish

coefplot (cinit27marg0, mcolor(gs0) msymbol(O)) || (cinit27marg1, mcolor(gs10) msymbol(D))  || (cinit27marg2, mcolor(gs0) msymbol(S)) ,  yline(0, lcolor(cranberry) lpatt(shortdash)) vertical byopts(row(1)) levels(95 90) ytitle("AME of Shared Right-Wing", size(medsmall)) ylabel(-.00005(.00001).00006) yline(-.00005, lcolor(gs10) lpatt(dot)) yline(.00006, lcolor(gs10) lpatt(dot))  saving(initmargins5.gph, replace)

est resto cinit32

eststo cinit32marg0: margins, dydx(envirodyad) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(0)) post vsquish

est resto cinit32
eststo cinit32marg1: margins, dydx(envirodyad) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(1)) post vsquish

est resto cinit32
eststo cinit32marg2: margins, dydx(envirodyad) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(2)) post vsquish

coefplot (cinit32marg0, mcolor(gs0) msymbol(O)) || (cinit32marg1, mcolor(gs10) msymbol(D))  || (cinit32marg2, mcolor(gs0) msymbol(S)) ,  yline(0, lcolor(cranberry) lpatt(shortdash)) vertical byopts(row(1)) levels(95 90) ytitle("AME of Shared Environmentalism", size(medlarge)) ylabel(-.00005(.00001).00006) yline(-.00005, lcolor(gs10) lpatt(dot)) yline(.00006, lcolor(gs10) lpatt(dot))  saving(initmargins6.gph, replace)


******************************************** ALTERNATE DV ***********************************************************


eststo tinit1: mlogit typeinitiation c.fariss##i.sharedideo2 $orgdyad0 $country, cluster(undir_id) base(0)

esttab tinit1 using sharedideo_tinit.tex, replace t(3) legend label collabels(none) varlabels(_cons Constant) se(3) pr2 b(3) star(* 0.10 ** 0.05 *** 0.01)

est resto tinit1
eststo tinit1marg0: margins, dydx(sharedideo2) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(0)) post vsquish

est resto tinit1
eststo tinit1marg1: margins, dydx(sharedideo2) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(1)) post vsquish

est resto tinit1
eststo tinit1marg2: margins, dydx(sharedideo2) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(2)) post vsquish

coefplot (tinit1marg0, mcolor(gs0) msymbol(O)) || (tinit1marg1, mcolor(gs10) msymbol(D))  || (tinit1marg2, mcolor(gs0) msymbol(S)) , yline(0, lcolor(cranberry) lpatt(shortdash)) vertical byopts(row(1)) levels(95 90) ytitle("AME of Shared Ideology", size(medsmall)) ylabel(-.00007(.00001).00006) yline(.00006, lcolor(gs10) lpatt(dot)) yline(-.00007, lcolor(gs10) lpatt(dot)) saving(tinitmargins.gph, replace)


******************************************** OLOGIT ***********************************************************


eststo ologit1: ologit continitiation c.fariss##i.sharedideo2 $orgdyad0 $country, cluster(undir_id) 

esttab ologit1 using sharedideo_ologit.tex, replace t(3) legend label collabels(none) varlabels(_cons Constant) se(3) pr2 b(3) star(* 0.10 ** 0.05 *** 0.01) mtitles("All Dyads" "Within Country" "Within Region" "Transnational")

******************************************** HDFE LPM ***********************************************************

/*  

ssc install ftools
ssc install reghdfe

gen contrhetinit=continitiation
replace contrhetinit=0 if continitiation==2

gen contrhet=contentordermiss0
replace contrhet=0 if contentordermiss0==2

gen contmatinit=continitiation
replace contmatinit=0 if continitiation==1
replace contmatinit=1 if continitiation==2

gen contmat=contentordermiss0
replace contmat=0 if contentordermiss0==1
replace contmat=1 if contentordermiss0==2 */

eststo lpm1: reghdfe contrhetinit c.fariss##i.sharedideo2 $orgdyad0 $country contmatinit, cluster(undir_id) abs(undir_id year)
eststo lpm2: reghdfe contmatinit c.fariss##i.sharedideo2 $orgdyad0 $country contrhetinit, cluster(undir_id) abs(undir_id year)

esttab lpm1 lpm2 using lpm.tex, replace t(3) legend label collabels(none) varlabels(_cons Constant) se(7) pr2 b(7) star(* 0.10 ** 0.05 *** 0.01) mtitles("Rhet. Initiation" "Mat. Initiation" "Rhet. Durability" "Mat. Durability")

est resto lpm1

coefplot lpm1, vert ci(90) drop($orgdyad0 $country contmatinit _cons) yline(0, lcolor(cranberry) lpatt(shortdash)) ytitle(Coefficient) saving("lpm1.gph", replace)

est resto lpm2

coefplot lpm2, vert ci(90) drop($orgdyad0 $country contrhetinit _cons) yline(0, lcolor(cranberry) lpatt(shortdash)) ytitle(Coefficient) saving("lpm2.gph", replace)

graph combine "lpm1.gph" "lpm2.gph", iscale(*.85) saving("lpm.gph", replace)


******************************************** DROP NON-GTD ***********************************************************


eststo gtdtest: mlogit continitiation c.fariss##i.sharedideo2 $orgdyad $country, cluster(undir_id) base(0)

esttab gtdtest using gtdtest.tex, replace t(3) legend label collabels(none) varlabels(_cons Constant) se(3) pr2 b(3) star(* 0.10 ** 0.05 *** 0.01) mtitles("All Dyads" "Within Country" "Within Region" "Transnational")


******************************************** NO ISIS or AL QAEDA ***********************************************************


eststo isisaqinit: mlogit continitiation c.fariss##i.sharedideo2 $orgdyad0 $country if isisaq==0, cluster(undir_id) base(0)

esttab isisaqinit using isisaq.tex, replace t(3) legend label collabels(none) varlabels(_cons Constant) se(3) pr2 b(3) star(* 0.10 ** 0.05 *** 0.01) mtitles("All Dyads" "Within Country" "Within Region" "Transnational")

est resto isisaqinit
eststo isisaqmarg0: margins, dydx(sharedideo2) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(0)) post vsquish

est resto isisaqinit
eststo isisaqmarg1: margins, dydx(sharedideo2) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(1)) post vsquish

est resto isisaqinit
eststo isisaqmarg2: margins, dydx(sharedideo2) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(2)) post vsquish

coefplot (isisaqmarg0, mcolor(gs0) msymbol(O)) || (isisaqmarg1, mcolor(gs10) msymbol(D))  || (isisaqmarg2, mcolor(gs0) msymbol(S)) , yline(0) vertical byopts(row(1)) levels(95 90) ytitle("Average Marginal Effect (AME) of Shared Ideology", size(medsmall)) ylabel(-.00008(.00001).00005) saving(isisaqmargs.gph, replace)


******************************************** ALTERNATE REPRESSION MEASURE ***********************************************************


eststo altrepr1: mlogit continitiation c.repression##i.sharedideo2 $orgdyad0 $country, cluster(undir_id) base(0)

esttab altrepr1 using altrepr1.tex, replace t(3) legend label collabels(none) varlabels(_cons Constant) se(3) pr2 b(3) star(* 0.10 ** 0.05 *** 0.01) mtitles("All Dyads" "Within Country" "Within Region" "Transnational")

est resto altrepr1
eststo altreprmarg0: margins, dydx(sharedideo2) at(repression=(0 8)) atmeans predict(outcome(0)) post vsquish

est resto altrepr1
eststo altreprmarg1: margins, dydx(sharedideo2) at(repression=(0 8)) atmeans predict(outcome(1)) post vsquish

est resto altrepr1
eststo altreprmarg2: margins, dydx(sharedideo2) at(repression=(0 8)) atmeans predict(outcome(2)) post vsquish

coefplot (altreprmarg0, mcolor(gs0) msymbol(O)) || (altreprmarg1, mcolor(gs10) msymbol(D))  || (altreprmarg2, mcolor(gs0) msymbol(S)) , yline(0) vertical byopts(row(1)) levels(95 90) ytitle("Average Marginal Effect (AME) of Shared Ideology", size(medsmall)) ylabel(-.00011(.00001).0001) saving(altreprmargs.gph, replace)


******************************************** IPTW ***********************************************************

/* gen highrep=.
 replace highrep=1 if fariss>=2.326128 & fariss!=.
replace highrep=0 if fariss<2.326128

eststo denom: reg highrep fariss_lag $orgdyad0 $country $region, cluster(undir_id)

predict denom if e(sample)
replace denom=denom*highrep+(1-denom)*(1-highrep)
sort undir_id year
by undir_id: replace denom=denom*denom[_n-1] if counter!=1 & denom[_n-1]!=.
sum denom, detail

eststo num: reg highrep fariss_lag ln_dist agediff ethfrac1 ethfrac2 $region, cluster(undir_id)

predict num if e(sample)
replace num=num*highrep+(1-num)*(1-highrep)
sort undir_id year
by undir_id: replace num=num*num[_n-1] if counter!=1 & num[_n-1]!=.
sum num, detail

gen weights=num/denom
sum weights if inrange(year,1950,2016), detail  */

eststo iptwinit: mlogit continitiation c.fariss##i.sharedideo2 $orgdyad0 $country [pw=weights], cluster(undir_id) base(0)

esttab iptwinit using iptw.tex, replace t(3) legend label collabels(none) varlabels(_cons Constant) se(3) pr2 b(3) star(* 0.10 ** 0.05 *** 0.01) mtitles("All Dyads" "Within Country" "Within Region" "Transnational")


******************************************** 2SRI ***********************************************************

/* eststo residuals: reg fariss fariss_lag $country $region, cluster(countrydyad)

predict residual_repression, residuals */

eststo init2sri: mlogit continitiation c.fariss##i.sharedideo2 $orgdyad0 $country residual_repression, cluster(undir_id) base(0)

esttab init2sri using twosri.tex, replace t(3) legend label collabels(none) varlabels(_cons Constant) se(3) pr2 b(3) star(* 0.10 ** 0.05 *** 0.01) mtitles("All Dyads" "Within Country" "Within Region" "Transnational")


******************************************** AREA DISAGGREGATION ***********************************************************

eststo area1: mlogit continitiation c.fariss##i.sharedideo2 $orgdyad0 $country if samecontig==1, cluster(undir_id) base(0)
eststo area2: mlogit continitiation c.fariss##i.sharedideo2 $orgdyad0 $country if transnational2==1, cluster(undir_id) base(0)

est resto area1
eststo area1marg0: margins, dydx(sharedideo2) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(0)) post vsquish

est resto area1
eststo area1marg1: margins, dydx(sharedideo2) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(1)) post vsquish

est resto area1
eststo area1marg2: margins, dydx(sharedideo2) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(2)) post vsquish

coefplot (area1marg0, mcolor(gs0) msymbol(O)) || (area1marg1, mcolor(gs10) msymbol(D))  || (area1marg2, mcolor(gs0) msymbol(S)) , yline(0) vertical byopts(row(1)) levels(95 90) ytitle("AME of Shared Ideology", size(medsmall)) ylabel(-.0009(.0001).0006) saving(regioninit.gph, replace)

est resto area2
eststo area2marg0: margins, dydx(sharedideo2) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(0)) post vsquish

est resto area2
eststo area2marg1: margins, dydx(sharedideo2) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(1)) post vsquish

est resto area2
eststo area2marg2: margins, dydx(sharedideo2) at(fariss=(.9509563 2.559293)) atmeans predict(outcome(2)) post vsquish

coefplot (area2marg0, mcolor(gs0) msymbol(O)) || (area2marg1, mcolor(gs10) msymbol(D))  || (area2marg2, mcolor(gs0) msymbol(S)) , yline(0) vertical byopts(row(1)) levels(95 90) ytitle("AME of Shared Ideology", size(medsmall)) ylabel(-.00003(.0000025).00003) saving(transinit.gph, replace)


